package com.kauidao.manageweb.feign.dictionary;


import com.kuaidao.common.constant.SysErrorCodeEnum;
import com.kuaidao.common.entity.IdEntity;
import com.kuaidao.common.entity.IdsEntity;
import com.kuaidao.common.entity.JSONResult;
import com.kuaidao.common.entity.PageBean;
import com.kuaidao.sys.dto.dictionary.DictionaryAddUpdateDTO;
import com.kuaidao.sys.dto.dictionary.DictionaryID;
import com.kuaidao.sys.dto.dictionary.DictionaryReqDTO;
import com.kuaidao.sys.dto.dictionary.DictionaryResDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.Valid;
import java.util.Dictionary;
import java.util.List;

@FeignClient(name = "sys-server", path = "/sys/dictionary", fallback = DictionaryFeignClient.HystrixClientFallback.class)
public interface DictionaryFeignClient{



    @PostMapping("/insertDictiondrt")
    public JSONResult insertDictiondrt(@RequestBody DictionaryAddUpdateDTO dictionaryAddUpdateDTO);

    @PostMapping("/findDictionaryByPage")
    public JSONResult<PageBean<DictionaryResDTO>> findDictionaryByPage(@RequestBody DictionaryReqDTO dictionaryReqDTO);

    @PostMapping("/updateDictionary")
    public JSONResult updateDictionary(@Valid @RequestBody DictionaryAddUpdateDTO dictionaryAddUpdateDTO);


    @RequestMapping("/findDictionaryByPrimaryKey")
    public JSONResult<DictionaryResDTO> findDictionaryByPrimaryKey(@RequestBody IdEntity idEntity);

    @PostMapping("/deleteDictionarys")
    public JSONResult deleteDictionarys(@RequestBody IdsEntity idsEntity);

//    @PostMapping("/deleteDictionarys")
//    public JSONResult deleteDictionarys(@RequestParam List<Long> primaryKey);
    @Component
    static class HystrixClientFallback implements DictionaryFeignClient{

        private JSONResult fallBackError(String name){
            return new JSONResult().fail(SysErrorCodeEnum.ERR_REST_FAIL.getCode(), SysErrorCodeEnum.ERR_REST_FAIL.getMessage());
        }

        @Override
        public JSONResult insertDictiondrt(DictionaryAddUpdateDTO dictionaryAddUpdateDTO) {
            return fallBackError("创建字典失败");
        }

        @Override
        public JSONResult<PageBean<DictionaryResDTO>> findDictionaryByPage(DictionaryReqDTO dictionaryReqDTO) {
            return fallBackError("查询字典主题列表失败");
        }

        @Override
        public JSONResult updateDictionary(DictionaryAddUpdateDTO dictionaryAddUpdateDTO) {
            return fallBackError("更新字典主题失败");
        }

        @Override
        public JSONResult<DictionaryResDTO> findDictionaryByPrimaryKey(IdEntity idEntity) {
            return  fallBackError("查询字典主题失败");
        }

    @Override
    public JSONResult deleteDictionarys(IdsEntity idsEntity) {
        return fallBackError("删除字典主题失败");
    }

//        @Override
//        public JSONResult deleteDictionarys(Long primaryKey) {
//            return fallBackError("删除字典主题失败");
//        }

    }




}
